﻿
Partial Class Paginas_OComprasConsulta
    Inherits System.Web.UI.Page

    Dim Url_destino As String = "2,OCOMPRASINGRESO.aspx?"


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Introducir aquí el código de usuario para inicializar la página
        If Not Page.IsPostBack Then
            Imprimir.Attributes.Add("onclick", "print();")
            Dim ACCION As String = Request.QueryString("ACCION")
            Dim resultado As New DataSet
            Dim Rutinas As New DataServices.Rutinas


            Session("accesos") = Request.QueryString("accesos")
            Call Rutinas.Valida_Acceso(sender, e, Page, "Form1", Session("accesos"))

        End If

    End Sub
    Protected Sub Buscar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Buscar.Click
        Busca(sender, e)

    End Sub

    Private Function Busca(ByVal sender As System.Object, ByVal e As System.EventArgs) As String

        Dim resultado As New DataSet
        Dim Rutinas As New DataServices.Rutinas
        Dim strscript As String

        Dim T_tabla As String = " From PEDIDOSENCABEZADO "
        Dim Csql As String = " SELECT ncodigo_pki as campo0, ncodigo_pki as campo1,  convert(varchar(10),dEmision,105) as campo2 "
        Csql = Csql & T_tabla & " where Cestado=1 "

        If Trim(dfec_ingd.Text) <> "" Then
            dfec_ingd = Rutinas.ffecha(dfec_ingd.Text)
        End If

        If Trim(dfec_ingh.Text) <> "" Then
            dfec_ingh = Rutinas.ffecha(dfec_ingh.Text)
        End If

        If Trim(ncodigo_pki.Text) <> "" Then
            Csql = Csql & " and ncodigo_pki like '%" & ncodigo_pki.Text & "%' "
        End If

        If Trim(nestado.SelectedValue) <> "0" Then
            Csql = Csql & " and nestado like '%" & nestado.Text & "%' "
        End If


        Csql = Csql & " order by ncodigo_pki"

        resultado = Rutinas.ExtraeSql(Csql)
        Try
            If Csql <> "" Then
                Call Rutinas.Grilla_link(resultado.Tables(0), grilla, Url_destino & "accion=1&", "Número Pedido", "Fecha Emisión")
            End If
        Catch ex As Exception

        End Try

    End Function

    Protected Sub agregar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles agregar.Click
        Response.Redirect(Mid(Url_destino, 3) & "accion=0")
    End Sub
End Class
